//Ray Zeller worked on this
#include "DayTime.h"
#include <string>
#include <iostream>
#include <math.h>

using namespace std;

static const int DAYS_PER_MONTH[] = 
	{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
static const string MONTHS[] = 
	{"January", "February", "March", "April", "May", "June", "July", "August", "September",
		"October", "November", "December"};
static const int GREGORIAN_START_YEAR = 1582;
static const int GREGORIAN_START_MONTH = 10;
static const int GREGORIAN_START_DAY = 15;
static const int JULIAN_END_DAY = 4;
static const int JANUARY = 1;
static const int FEBRUARY = 2;
static const int DECEMBER = 12;
static const int MIDNIGHT = 24;
static const int ANHOUR = 60;
static const int ELEVENPM = 23;

DayTime::DayTime()
{
}

DayTime::DayTime(int aYear, int aMonth, int aDate){
myYear=aYear;
myMonth=aMonth;
myDate=aDate;;
myTime = -1.00;
}
DayTime::DayTime(double aTime){
	myYear=0;
	myMonth=0;
	myDate=0;
	myTime=aTime;
}
string DayTime::getYear(){
	if(myYear==0)
		return 0;
	stringstream year;
	year << myYear;
	return year.str();
}
string DayTime::getMonth(){
	if(myMonth==0)
		return "";
	return MONTHS[myMonth-1];
}
string DayTime::getDate(){
	if(myDate==0)
		return "";
	stringstream date;
	date << myDate;
	return date.str();
}
string DayTime::getHour(){
	stringstream hour;
	hour << int(myTime);
	return hour.str();
}
string DayTime::getMinute(){
	stringstream m;
	double minute = myTime - floor(myTime);
	cout<<minute;
	minute *=100.00;
	m << (int)round(minute);
	if(minute>=10.00)
		return m.str();
	return "0" + m.str();
}
int DayTime::getHourInt(){
	return int(myTime);
}
int DayTime::getMinuteInt(){
	double minute = myTime - floor(myTime);
	minute *=100.00;
	return ((int)round(minute));
}
int DayTime::daysPerMonth(int y, int m){
	int days = DAYS_PER_MONTH[m-1];
	if (m == FEBRUARY && isLeapYear(y))
		days++;
	return days;
}
bool DayTime::isLeapYear(int y){
	if (y % 4 != 0) return false;
	if (y < GREGORIAN_START_YEAR) return true;
	return (y % 100 != 0) || (y % 400 == 0);
}

string DayTime::getFullDate(){
	if(getYear()=="")
		return "";
	return getMonth()+" "+ getDate() + ", " + getYear();
}
DayTime::~DayTime()
{
}
